<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>page</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" name="body">
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <input type="text" name="username" id="username" required lay-verify="required" placeholder="请输入用户名"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">密码</label>
    <div class="layui-input-inline">
      <input type="text" name="password" id="password" required lay-verify="required" placeholder="请输入密码"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">激活</label>
    <div class="layui-input-inline">
      <input type="checkbox" name="activate" id="activate" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">邮箱</label>
    <div class="layui-input-inline">
      <input type="text" name="email" id="email" required lay-verify="required|email" placeholder="请输入email"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">电话</label>
    <div class="layui-input-inline">
      <input type="number" name="phone" id="phone" required lay-verify="required|phone|number" placeholder="请输入电话"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">性别</label>
    <div class="layui-input-inline">
      <input id="LAY-user-reg-man" type="radio" name="gender" value="男" title="男" checked>
      <input id="LAY-user-reg-woman" type="radio" name="gender" value="女" title="女">
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-inline">
      <input type="text" name="remake" id="remake" placeholder="请输入备注" autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="user">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<script src="layui/layui.js" charset="utf-8"></script>

<script>
  //Demo
  layui.use(['form', 'jquery'], function () {
    let form = layui.form;
    let $ = layui.$;
    form.on('submit()', function () {
      let parameter = $("form").serialize();
      $.ajax({
        type: 'post',
        data: parameter,
        url: './userInsert',
        success: function (data) {
          if (data) {
            layer.alert("提交成功");
            layer.close(layer.index);
            window.parent.location.reload();
          } else {
            layer.alert("提交失败")
          }
        }
      });
      return false;
    });
  });
</script>
</body>
</html>